package com.tf_cut.backend.cpm.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.tf_cut.backend.common.pojo.PageInfo;
import com.tf_cut.backend.common.pojo.Result;
import com.tf_cut.backend.cpm.service.CpmInsideTransComService;
import com.tf_cut.backend.cpm.vo.CpmInsideTransComVo;

import lombok.extern.slf4j.Slf4j;


@RestController
@RequestMapping("/backend/cpm/")
@Slf4j
public class CpmInsideTransController {
	
	@Autowired
	private CpmInsideTransComService cpmInsideTransComService;
	
	// 获取代理商季度待结分润
	@RequestMapping("getQuarterCommission")
    public String getQuarterCommission(String json) {
		Result<PageInfo<CpmInsideTransComVo>> result = null;
		try {
			CpmInsideTransComVo vo = JSON.parseObject(json, CpmInsideTransComVo.class);
			result = Result.of(cpmInsideTransComService.findQuarterCommission(vo));
		}catch (Exception e) {
			String msg = "查询代理商季度待结分润失败！condition："+json;
			log.error(msg, e);
			result = Result.of(null, false, msg);
		}
        return JSON.toJSONString(result,SerializerFeature.WriteDateUseDateFormat);
    }
	
	// 获取代理商季度待结分润
	@RequestMapping("payQuarter")
    public String payQuarter(String ids,String type) {
		Result<String> result = Result.of("支付代理商季度待结分润成功！");
		try {
			cpmInsideTransComService.updatePayQuarter(ids,type);
		}catch (Exception e) {
			String msg = "支付代理商季度待结分润失败！condition："+ids;
			log.error(msg, e);
			result = Result.of(msg, false);
		}
        return JSON.toJSONString(result);
    }
}
